package ltd.dujiabao.servicebase.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author : DuJiabao
 * @Project : online-course-project
 * @Time : 2021/4/19 10:21
 * @Desc : MyBatis自动填充的处理器类
 */
@Component
public class TableFieldFillHandler implements MetaObjectHandler {
  @Override
  public void insertFill(MetaObject metaObject) {
    this.setFieldValByName("isDeleted", false, metaObject);
    this.setFieldValByName("gmtCreate", new Date(), metaObject);
    this.setFieldValByName("gmtModified", new Date(), metaObject);
  }

  @Override
  public void updateFill(MetaObject metaObject) {
    this.setFieldValByName("gmtModified", new Date(), metaObject);
  }
}
